using System;
using Kopernikus.Parsing.GenericActions;

namespace Kopernikus.Parsing.GenericParsing
{
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
    public class CfgAttribute : Attribute
    {
        private readonly string m_productionText;
        private ISemanticActionParametersFixup m_parametersFixup;
        private Production m_production;

        public CfgAttribute(string productionText)
        {
            m_productionText = productionText;
        }

        public Production Production
        {
            get
            {
                InitProduction();
                return m_production;
            }
        }

        public ISemanticActionParametersFixup ParametersFixup
        {
            get
            {
                InitProduction();
                return m_parametersFixup;
            }
        }

        private void InitProduction()
        {
            if (m_production == null)
            {
                m_production = Production.Parse(m_productionText, out m_parametersFixup);
            }
        }
    }
}